import { tokenName } from "@/server/base"

export type roleState = {
  roleUserMenu: string[],
}

let state: roleState = {
  roleUserMenu: [],
}

let getters = {
  roleUserMenuName(state: any) {
    const menuName = state.roleUserMenu;
    if (menuName && menuName.length > 0) {
      return menuName;
    }
    const str = localStorage.getItem(tokenName + '_menu');
    if (!str) {
      return []
    }
    return JSON.parse(str);
  }
}
let mutations = {
  roleUserMenuName(state: any, roleUserMenu: string[]) {
    localStorage.setItem(tokenName + '_menu', JSON.stringify(roleUserMenu));
    state.roleUserMenu = roleUserMenu
  }
}
let actions = {}
export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
